// 导入路由
import VueRouter from "vue-router";
// 导入vue
import Vue from "vue";
// 路由注册
Vue.use(VueRouter);
import login from "@/views/login/login.vue";
import layout from "@/views/layout/layout.vue";
import chart from "@/views/layout/chart/chart.vue";
import user from "@/views/layout/user/user.vue";
import question from "@/views/layout/question/question.vue";
import business from "@/views/layout/business/business.vue";
import subject from "@/views/layout/subject/subject.vue";
// 路由实例化
const router = new VueRouter({
  routes: [
    { path: "/", redirect: "/login" },
    {
      path: "/login",
      component: login,
      meta: {
        title: "登录",
      },
    },
    {
      path: "/layout",
      component: layout,
      redirect: "/layout/chart",
      children: [
        {
          path: "/layout/chart",
          component: chart,
          // 配置路由元
          meta: {
            title: "数据概览",
          },
        },
        {
          path: "/layout/user",
          component: user,
          meta: {
            title: "用户列表",
          },
        },
        {
          path: "/layout/question",
          component: question,
          meta: {
            title: "题库列表",
          },
        },
        {
          path: "/layout/business",
          component: business,
          meta: {
            title: "企业列表",
          },
        },
        {
          path: "/layout/subject",
          component: subject,
          meta: {
            title: "学科列表",
          },
        },
      ],
    },
  ],
});
// 进度条
import Nprogress from "nprogress";
import "nprogress/nprogress.css";
// 路由前置守卫
router.beforeEach((to, from, next) => {
  console.log("to", to);
  console.log("from", from);
  Nprogress.start();
  next();
});
router.afterEach((to, from) => {
  Nprogress.done();
  // 修改标题的简写模式
  document.title = to.meta.title;
  // console.log("to", to);
  console.log("from", from);
});
// 输出路由
export default router;
